﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;

namespace Login
{
    public partial class Form2 : Form
    {
        SqlConnection con;
        SqlDataAdapter adap;
        DataSet ds;
        SqlCommandBuilder cmdbl;
        public Form2()
        {
            InitializeComponent();
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                cmdbl = new SqlCommandBuilder(adap);
                adap.Update(ds, "Users");
                MessageBox.Show("Updated ok", "update", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);  
            }
        }

        private void Form2_Load(object sender, EventArgs e)
        {
           
            try
            {
                SqlConnection con = Program.GetConnection;
                adap = new SqlDataAdapter("SELECT * FROM Users",con);
                ds = new System.Data.DataSet();
                adap.Fill(ds, "Users");
                dataGridView1.DataSource = ds.Tables[0];
                //SqlDataReader dr = null;
                //SqlCommand cmd = new SqlCommand("SELECT * FROM Users WHERE LoginName ='" +
                //    txtName.Text + "' AND Password='" + txtpassword.Text + "'", con);
                //dr = cmd.ExecuteReader();
                //if (dr.Read())
                //{
                //    Program.UserLoginName = dr.GetString(3);
                //    this.Close();
                //}
                //else
                //    MessageBox.Show("Invalid Username and Password!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
